﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BOSS.Domain;

namespace BOSS.Dao
{
    /// <summary>
    /// 实体 DAO(数据访问对象)
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    /// <typeparam name="IdT">ID 类型</typeparam>
    public interface IEntityDao<T, IdT> where T : IEntity<IdT>
    {
        /// <summary>
        /// 根据 ID 查找实体。找不到则返回 null
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T FindById(IdT id);

        /// <summary>
        /// 分页查找所有实体
        /// </summary>
        /// <returns></returns>
        IList<T> SelectAll();

        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        IdT Save(T entity);

        /// <summary>
        /// 更新指定的实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);

        /// <summary>
        /// 保存或更新实体
        /// </summary>
        /// <param name="entity"></param>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 刷新实体（即从数据库中重新获取相应值）
        /// </summary>
        /// <param name="entity"></param>
        void Refresh(T entity);

        /// <summary>
        /// 将实体从会话缓存中移除
        /// </summary>
        /// <param name="entity"></param>
        void Evict(T entity);

        /// <summary>
        /// 将实体与会话重新关联
        /// </summary>
        /// <param name="entity"></param>
        void Lock(T entity);

        /// <summary>
        /// 将当前挂起的各项操作（save、update、delete）刷新到数据库中
        /// </summary>
        void Flush();

        /// <summary>
        /// 清除当前会话缓存中的所有数据，取消挂起的各项操作（save、update、delete）
        /// </summary>
        void Clear();

    }
}
